<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title th:if="${tableFlowRowsDTO.taskSelectFlag}==null">数据流程管理</title>
    <title th:if="${tableFlowRowsDTO.taskSelectFlag}!=null">数据流程选择</title>

    <script th:inline="javascript">
        function confirmAction(action, flowFormatId, onLineFlag) {
            var url = "";
            var info = "";
            if (action == "delete") {
                info = "确认删除?";
                url = '/datakit/table/flow/rows/operate?flowFormatId=' + flowFormatId + "&action=1";
            } else if (action == "online") {
                info = "确认申请上线?";
                url = '/datakit/table/flow/rows/operate?flowFormatId=' + flowFormatId + "&action=2";
            } else if (action == "offline") {
                info = "确认申请下线?";
                url = '/datakit/table/flow/rows/operate?flowFormatId=' + flowFormatId + "&action=3";
            } else if (action == "detail") {
                url = '/datakit/table/flow/query?flowFormatId=' + flowFormatId + '&pageNum=1&viewFlag=1';
            } else if (action == "edit") {
                url = '/datakit/table/flow/query?flowFormatId=' + flowFormatId + '&pageNum=1&viewFlag=2';
            } else if (action == "add") {
                url = '/datakit/table/flow/query?flowFormatId=-1&pageNum=1&viewFlag=2';
            } else if (action == "copy") {
                info = "确认复制该表对象?";
                url = '/datakit/table/flow/rows/operate?flowFormatId=' + flowFormatId + "&action=4";
            }

            if (action == "create" || action == "online" || action == "offline" || action == "copy") {
                if (confirm(info)) {
                    window.location.href = url;
                }
            } else if (action == "delete") {
                if (onLineFlag != "0") {
                    alert("请先申请表实例下线!")
                } else {
                    if (confirm(info)) {
                        window.location.href = url;
                    }
                }
            } else if (action == "detail" || action == "add") {
                window.location.href = url;
            } else if (action == "edit") {
                if (onLineFlag != "0") {
                    alert("请先申请表实例下线!")
                } else {
                    window.location.href = url;
                }
            }
        }

        function taskSelectCloseWindow() {
            if (document.getElementById('taskSelectedObjectId').value > 0) {
                //当前子页面选择的数据保存到父页面上
                window.opener.setValueFromChildPage([[${tableFlowRowsDTO.taskSelectFlag}]],
                    document.getElementById('taskSelectedObjectId').value,
                    document.getElementById('taskSelectedObjectName').value);
            }
            window.close(); // 关闭新窗口
        }

        function toggleSelection(objectId, objectName) {
            var taskSelectedObjectId = document.getElementById('taskSelectedObjectId');
            if (taskSelectedObjectId.value === objectId) {
                taskSelectedObjectId.value = '';
            } else {
                taskSelectedObjectId.value = objectId;
            }

            var taskSelectedObjectName = document.getElementById('taskSelectedObjectName');
            if (taskSelectedObjectName.value === objectName) {
                taskSelectedObjectName.value = '';
            } else {
                taskSelectedObjectName.value = objectName;
            }
        }
    </script>

    <style>
        /* 定义鼠标悬停时的行颜色 */
        tr:hover {
            background-color: #f5f5f5;
        }

        /* 定义特定类名的行鼠标悬停颜色 */
        tr.specific-row:hover {
            background-color: #e0e0e0;
        }

        .text-ellipsis {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            max-width: 150px; /* Adjust the width as needed */
        }
    </style>
    <link rel="stylesheet" href="/css/navbar.css" type="text/css">
</head>

<body>
<div th:if="${tableFlowRowsDTO.taskSelectFlag}==null" th:insert="~{common/commons::navbar}"></div>

<div class="navbar-div-right" id="content">
    <input type="hidden" id="taskSelectedObjectId" th:value="${taskSelectedObjectId}"/>
    <input type="hidden" id="taskSelectedObjectName" th:value="${taskSelectedObjectName}"/>

    <div style="width:1200px;margin:20px auto 0px auto;">
        <form method="get" th:action="@{'/datakit/tableFlowRows/query'}" th:object="${tableFlowRowsDTO}">
            状态:
            <select th:if="${tableFlowRowsDTO.taskSelectFlag}==null" name="onLineFlag" th:field="*{onLineFlag}">
                <option th:value="-1" selected="selected">全部</option>
                <option th:value="0"> 上线</option>
                <option th:value="1"> 下线</option>
            </select>
            <select th:if="${tableFlowRowsDTO.taskSelectFlag}!=null" name="onLineFlag" th:field="*{onLineFlag}">
                <option th:value="1" selected="selected"> 上线</option>
            </select>
            &nbsp
            <input type="submit" value="查询"/>
            &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
            &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
            &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
            <button th:if="${tableFlowRowsDTO.taskSelectFlag}==null" th:onclick="confirmAction( 'add');return false;">
                新增
            </button>
            <button th:if="${tableFlowRowsDTO.taskSelectFlag}==null">刷新</button>

            <button th:if="${tableFlowRowsDTO.taskSelectFlag}!=null" th:onclick="taskSelectCloseWindow()">确认</button>
            <input th:if="${tableFlowRowsDTO.taskSelectFlag}!=null" type="hidden" th:field="*{taskSelectFlag}"
                   th:value="${tableFlowRowsDTO.taskSelectFlag}"/>
        </form>
    </div>

    <div style="width:1200px;margin:0px auto 0px auto;">
        <table style="width:1200px;margin:auto auto;">
            <thead>
            <tr>
                <th>流程ID</th>
                <th>流程名称</th>
                <th>源端</th>
                <th>目标端</th>
                <th>发布状态</th>
                <th>创建时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="iterator,rowNumber : ${pageInfo.list}"
                th:onclick="toggleSelection([[${iterator.flowFormatId}]],[[${iterator.flowName}]])">
                <td th:text=" ${iterator.flowFormatId}"></td>
                <td th:text="${iterator.flowName}"></td>
                <td class="text-ellipsis" th:text="${iterator.sourceJdbcUrl}" th:title="${iterator.sourceJdbcUrl}"></td>
                <td class="text-ellipsis" th:text="${iterator.targetJdbcUrl}" th:title="${iterator.targetJdbcUrl}"></td>
                <td th:text="${iterator.onLineFlagName}"></td>
                <td th:text="${#dates.format(iterator.createDate, 'yyyy-MM-dd HH:mm:ss')}"></td>
                <td>
                    <button th:if="${tableFlowRowsDTO.taskSelectFlag}==null"
                            th:onclick="confirmAction( 'detail',[[${iterator.flowFormatId}]])">详情
                    </button>
                    <button th:if="${tableFlowRowsDTO.taskSelectFlag}==null"
                            th:onclick="confirmAction( 'edit',[[${iterator.flowFormatId}]],[[${iterator.onLineFlag}]])">
                        编辑
                    </button>
                    <button th:if="${tableFlowRowsDTO.taskSelectFlag==null && iterator.onLineFlag==0}"
                            th:onclick="confirmAction( 'online',[[${iterator.flowFormatId}]])">
                        上线
                    </button>
                    <button th:if="${tableFlowRowsDTO.taskSelectFlag==null && iterator.onLineFlag==1}"
                            th:onclick="confirmAction( 'offline',[[${iterator.flowFormatId}]])">
                        下线
                    </button>
                    <button th:if="${tableFlowRowsDTO.taskSelectFlag}==null"
                            th:onclick="confirmAction( 'delete',[[${iterator.flowFormatId}]],[[${iterator.onLineFlag}]])">
                        删除
                    </button>
                    <input th:if="${tableFlowRowsDTO.taskSelectFlag}!=null"
                           id="table-input-radio-id" name="input-radio-name" type="radio"
                           th:value="${iterator.flowFormatId}">
                </td>
            </tr>
            <tr th:if="${pageLeftSize!=0}" th:each="i:${#numbers.sequence(1,pageLeftSize)}">
                <td>&nbsp</td>
                <td>&nbsp</td>
                <td>&nbsp</td>
                <td>&nbsp</td>
                <td>&nbsp</td>
                <td>&nbsp</td>
                <td>&nbsp</td>
            </tr>
            </tbody>
        </table>
    </div>

    <!-- 展示页码 -->
    <div style="text-align: center"
         th:with="urlPrefix='/datakit/tableFlowRows/query?pageNum=',urlSuffix='&onLineFlag='+${tableFlowRowsDTO.onLineFlag}">
        <div th:insert="common/commons::fragment-page(${urlPrefix},${urlSuffix})"></div>
    </div>

    <div style="display: none;"
         th:insert="common/commons::fragment-result(${resultCode},${resultMessage},${resultHref})"></div>
</div>
</body>
</html>